- import_playbook: "/srv/web/infra/ansible/playbooks/include/virt-create.yml myhosts=openqa:openqa_lab"

- name: setup base openQA host
  hosts: openqa:openqa_lab
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  pre_tasks:
  - include_vars: dir=/srv/web/infra/ansible/vars/all/ ignore_files=README
  - import_tasks: "{{ tasks_path }}/yumrepos.yml"

  roles:
   - { role: base, tags: ['base'] }
   - { role: rkhunter, tags: ['rkhunter'] }
   - { role: nagios_client, tags: ['nagios_client'] }
   - { role: hosts, tags: ['hosts']}
   - ipa/client
   - { role: collectd/base, tags: ['collectd_base'] }
   - { role: sudo, tags: ['sudo'] }
   - apache

  tasks:
  - import_tasks: "{{ tasks_path }}/motd.yml"

  handlers:
   - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: configure fedora-messaging queues on openQA servers
  hosts: openqa:openqa_lab
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - role: rabbit/queue
    username: "openqa"
    queue_name: "openqa{{ openqa_env_suffix }}_scheduler"
    routing_keys: "{{ openqa_amqp_scheduler_routing_keys }}"
    write_queues:
        - "ci"
        - "openqa"
    vars:
      # yes, even the staging scheduler listens to production, it
      # has to or else it wouldn't schedule any jobs
      env: "production"
      env_suffix: ""
    tags: ['rabbit']
  - role: rabbit/queue
    username: "openqa{{ openqa_env_suffix }}"
    queue_name: "openqa{{ openqa_env_suffix }}_resultsdb_reporter"
    routing_keys: "{{ openqa_amqp_resultsdb_reporter_routing_keys }}"
    write_queues:
        - "ci"
        - "openqa"
    vars:
      # for this role to work correctly we do need to look like a
      # staging server
      env: "{{ openqa_env }}"
      env_suffix: "{{ openqa_env_suffix }}"
    tags: ['rabbit']
  - role: rabbit/queue
    username: "openqa{{ openqa_env_suffix }}"
    queue_name: "openqa{{ openqa_env_suffix }}_wiki_reporter"
    routing_keys: "{{ openqa_amqp_wiki_reporter_routing_keys }}"
    write_queues:
        - "ci"
        - "openqa"
    vars:
      # for this role to work correctly we do need to look like a
      # staging server
      env: "{{ openqa_env }}"
      env_suffix: "{{ openqa_env_suffix }}"
    tags: ['rabbit']
    # relvalconsumer queue, we still use openqa auth for this as it's
    # easy that way
  - role: rabbit/queue
    username: "openqa"
    queue_name: "openqa_relvalconsumer{{ relvalconsumer_env_suffix }}"
    routing_keys: "{{ relvalconsumer_amqp_routing_keys }}"
    write_queues:
        - "ci"
        - "openqa"
    vars:
      # yes, even the staging scheduler listens to production, it
      # has to or else it wouldn't schedule any jobs
      env: "production"
      env_suffix: ""
    tags: ['rabbit']
    when: "relvalconsumer_env_suffix is defined"
    # relvalamiconsumer queue, we still use openqa auth for this as it's
    # easy that way
  - role: rabbit/queue
    username: "openqa"
    queue_name: "openqa_relvalamiconsumer{{ relvalconsumer_env_suffix }}"
    routing_keys: "{{ relvalamiconsumer_amqp_routing_keys }}"
    write_queues:
        - "ci"
        - "openqa"
    vars:
      # yes, even the staging updater listens to production, it
      # has to as we never publish fedimg.image.publish on stg
      env: "production"
      env_suffix: ""
    tags: ['rabbit']
    when: "relvalconsumer_env_suffix is defined"

    # check-compose queue, we still use openqa auth for this as it's
    # easy that way
  - role: rabbit/queue
    username: "openqa{{ checkcompose_env_suffix }}"
    queue_name: "openqa{{ checkcompose_env_suffix }}_checkcomp"
    routing_keys: "{{ checkcompose_amqp_routing_keys }}"
    write_queues:
        - "ci"
        - "openqa"
    vars:
      # for this role to work correctly we do need to look like a
      # staging server
      env: "{{ checkcompose_env }}"
      env_suffix: "{{ checkcompose_env_suffix }}"
    tags: ['rabbit']
    when: "checkcompose_env_suffix is defined"

    # fedora_nightlies queue, we still use openqa auth for this as it's
    # easy that way
  - role: rabbit/queue
    username: "openqa"
    queue_name: "openqa_fedora_nightlies"
    routing_keys: "{{ fedora_nightlies_amqp_routing_keys }}"
    write_queues:
        - "ci"
        - "openqa"
    vars:
      env: "production"
    tags: ['rabbit']
    when: "fedora_nightlies_amqp_queue is defined"

- name: set up openQA server data NFS mounts (staging)
  hosts: openqa_lab

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - role: nfs/client
    mnt_dir: '/var/lib/openqa/testresults'
    nfs_src_dir: 'fedora_openqa_lab/testresults'
    nfs_mount_opts: 'rw,bg,nfsvers=3'
    tags: ['nfs_client']
  - role: nfs/client
    mnt_dir: '/var/lib/openqa/images'
    nfs_src_dir: 'fedora_openqa_lab/images'
    nfs_mount_opts: 'rw,bg,nfsvers=3'
    tags: ['nfs_client']

  handlers:
   - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: set up openQA server data NFS mounts (prod)
  hosts: openqa

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - role: nfs/client
    mnt_dir: '/var/lib/openqa/testresults'
    nfs_src_dir: 'fedora_openqa/testresults'
    nfs_mount_opts: 'rw,bg,nfsvers=3'
    tags: ['nfs_client']
  - role: nfs/client
    mnt_dir: '/var/lib/openqa/images'
    nfs_src_dir: 'fedora_openqa/images'
    nfs_mount_opts: 'rw,bg,nfsvers=3'
    tags: ['nfs_client']

  handlers:
   - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: configure openQA
  hosts: openqa:openqa_lab
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

# relvalconsumer isn't particularly related to openQA in any way, we
# just put that role on these boxes. There's nowhere more obviously
# correct for it, really. Ditto fedora_nightlies and testcase_stats
  roles:
   - { role: openqa/server, tags: ['openqa_server'] }
   - { role: openqa/dispatcher, tags: ['openqa_dispatcher'] }
   - { role: check-compose, tags: ['check-compose'], when: "checkcompose_env_suffix is defined" }
   - { role: relvalconsumer, tags: ['relvalconsumer'], when: "relvalconsumer_env_suffix is defined" }
   - { role: fedora_nightlies, tags: ['fedora_nightlies'], when: "fedora_nightlies_amqp_queue is defined" }
   - { role: testcase_stats, tags: ['testcase_stats'], when: "testcase_stats_output_dir is defined" }

  handlers:
   - import_tasks: "{{ handlers_path }}/restart_services.yml"
